;
$(function() {
	$.suredy = $.extend({}, $.suredy);

	// 修改控件状态颜色
	var changeStatus = function($ele, alarm) {
		if (alarm) {
			$ele.parents('.form-group').addClass('has-error');

			$ele.one('change', function() {
				$ele.parents('.form-group').removeClass('has-error');
			});
		} else {
			$ele.parents('.form-group').removeClass('has-error');
		}
	};

	// 空值校验
	var notNullChecker = function($form) {
		var alarm = false;

		var $formData = $('.not-empty', $form);

		$formData.each(function(i) {
			var $this = $(this);
			var isEmpty = false;

			if (!$this.val())
				isEmpty = true;

			// 空值
			if (isEmpty)
				alarm = true;

			changeStatus($this, isEmpty);
		});

		if (alarm)
			alert('请正确填写信息，[ * ]为必填项！');

		return !alarm;
	};

	// 判断数字
	var numberChecker = function($form) {
		var alarm = false;

		var $formData = $('.number', $form);

		$formData.each(function(i) {
			var $this = $(this);
			var val = $this.val();

			if (val !== '') {
				var notNum = !$.isNumeric($this.val());

				// 非数字
				if (notNum)
					alarm = true;

				changeStatus($this, notNum);
			}
		});

		if (alarm)
			alert('数字项填写错误，请正确填写！');

		return !alarm;
	};

	$.suredy.formChecker = function($form) {
		return notNullChecker($form) && numberChecker($form);
	};

});